package com.matrix.java.chap_04;

import java.util.Scanner;

/*
    财务应用：货币单位
 */
public class Ex4_26 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter an amount in double, for example 11.56: ");
        String amount = input.next();
        //判断小数点的存在以及位数
        int pointIndex = amount.indexOf(".");
        if (pointIndex < 0) {
            //为整数直接输出
            System.out.println(amount + " dollars");
            return;
        }
        //不为整数
        String decimalString = amount.substring(pointIndex+1);
        String integerString = amount.substring(0, pointIndex);
        int demical = Integer.parseInt(decimalString);
        int numberOfQuarters = demical / 25;
        int remainingAmount = demical % 25;
        int numberOfDimes = remainingAmount / 10;
        remainingAmount %= 10;
        int numberOfNickels = remainingAmount / 5;
        remainingAmount %= 5;
        int numberOfPennies = remainingAmount;
        System.out.println(integerString + " dollars");
        System.out.println(numberOfQuarters + " quarters");
        System.out.println(numberOfDimes + " dimes");
        System.out.println(numberOfNickels + " nickels");
        System.out.println(numberOfPennies + " pennies");
        input.close();
    }
}
